
public class Pixel 
{
    private static final int COLOR_TYPE_RED = 16;
    private static final int COLOR_TYPE_GREEN = 8;
    private static final int COLOR_TYPE_BLUE = 0;
	int r;
	int g; 
	int b;
	
	public Pixel(int r, int g, int b) 
	{	
		this.r = r;
		this.g = g;
		this.b = b;
	}
	
    public Pixel(int pixelAsInt) {
        r = getColor(pixelAsInt, COLOR_TYPE_RED);
        g = getColor(pixelAsInt, COLOR_TYPE_GREEN);
        b = getColor(pixelAsInt, COLOR_TYPE_BLUE);
    }
    
    private int getColor(int pixel, int colorType) {
        return ((pixel >> colorType) & 0xFF);
    }
    
    public int toInt() 
    {
        int x = (0xFF << 24 | (int) r << COLOR_TYPE_RED | (int) g << COLOR_TYPE_GREEN | (int) b << COLOR_TYPE_BLUE);
        return x;
    }
}
